package com.situ.day9;

public class Student {
	private int id; // 1
	private String name; // 张三
	private int age;// 23
	private String className; // Java190703 String类型的默认值是null
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	
	public int getAge() {
		return age;
	}
	
	public void setAge(int age) {
		   // 对非法的年龄进行控制
		   if (age > 0 && age <= 120) {
		     this.age = age;
		   }
		}
	
	public String getClassName() {
		return className;
	}
	
	public void setClassName(String className) {
		this.className = className;
	}

	// 无参构造方法
	// 如果不写，Java默认提供一个无参构造方法
	// 如果你写了，Java就不会再提供这个无参的构造方法
	public Student() {
		System.out.println("Student.Student()");
	}

	public Student(int id, String name, int age, String className) {
		System.out.println("Student.Student() ----");
		// The assignment to variable id has no effect
		// id = id;
		// this代表当前对象
		this.id = id;
		this.name = name;
		this.age = age;
		this.className = className;
	}

	// 方法（功能）
	public void study() {
		// System.out.println("张三正在Java90703班学习");
		System.out.println(name + "正在" + className + "班学习");
	}

	@Override
	public String toString() {
		return "Student [id=" + id + ", name=" + name + ", age=" + age + ", className=" + className + "]";
	}

	public static void main(String[] args) {
		// new的是无参构造方法
		Student student1 = new Student();
		student1.id = 1;
		student1.name = "张三";
		System.out.println(student1);

		// new的是有参构造方法
		Student student2 = new Student(2, "lisit", 23, "Java1907");
		System.out.println(student2.name);
		System.out.println(student2);
	}
}
